#include <stdio.h>
#include <string.h>

#define KEYBOARD_INPUT_SIZE 256
#define COMPARE_SUB 4

void print_lines_with(char input_line[KEYBOARD_INPUT_SIZE], char contains[KEYBOARD_INPUT_SIZE]);

// prints a string of keyboard input if that string contains
//    a string input as a cmd argument
int main(int argc, char *argv[]) {
	char keyboard_input[KEYBOARD_INPUT_SIZE];
	char match_string[KEYBOARD_INPUT_SIZE];

	if (argv[1] != NULL) {
		printf("String to match is '%s'\n", argv[1]);

		do {
			printf("Input: ");
			fgets(keyboard_input, sizeof keyboard_input, stdin);
			print_lines_with(keyboard_input, argv[1]);

		} while(strncmp(keyboard_input, "EXIT", COMPARE_SUB) != 0 && strncmp(keyboard_input, "exit", COMPARE_SUB) != 0);
	} else {
		printf("Please run as follows: ./num6 <string_to_match>\n");
	}
}

// checks for a match of contains in input_line
// prints Match or No Match accordingly
void print_lines_with(char input_line[KEYBOARD_INPUT_SIZE], char contains[KEYBOARD_INPUT_SIZE]) {
	if (strncmp(input_line, "EXIT", COMPARE_SUB) != 0 && strncmp(input_line, "exit", COMPARE_SUB) != 0) {
		if (strstr(input_line, contains) != NULL) {
			printf("Match: %s", input_line);
		} else {
			printf("No Match\n");
		}
	}
}